var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/express/base.tsx
var base_exports = {};
__export(base_exports, {
  default: () => base_default
});
module.exports = __toCommonJS(base_exports);
var import_icons = require("@ant-design/icons");
var import_ahooks = require("ahooks");
var import_react = require("react");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_functionInfo = __toESM(require("./component/functionInfo"));
var import_selectCtx = __toESM(require("./component/selectCtx"));
var import_textareaEditor = __toESM(require("./component/textareaEditor"));
var import_service = require("./service");
function base_default({ type, value }) {
  const [getRef] = (0, import_util.useRefs)();
  const [ins, { params }] = (0, import_functionalComponent.useModal)();
  const [currentFunc, setCurrentFunc] = (0, import_react.useState)(null);
  const editor = (0, import_react.useRef)(null);
  const validExpress = async () => {
    var _a, _b;
    const t = (_a = editor.current) == null ? void 0 : _a.getHtmlValue();
    try {
      if (t) {
        const text = t;
        const d = await (0, import_service.expressionValidate)({ ...type.value, expressionDisplay: text });
        (_b = getRef("FunctionInfo").current) == null ? void 0 : _b.changeActiveKeyAndParmam("2", d == null ? void 0 : d.validateMsg);
        return d;
      }
    } catch {
      import_functionalComponent.message.warn("接口报错");
    }
  };
  (0, import_react.useEffect)(() => {
    var _a;
    if (value) {
      (_a = editor.current) == null ? void 0 : _a.setDefaultHtml((value == null ? void 0 : value.label) ?? "");
    }
  }, [value]);
  (0, import_react.useEffect)(() => {
    ins.setApi({ getValue });
  }, []);
  const getValue = async () => {
    const res = await validExpress();
    return res;
  };
  (0, import_ahooks.useEventListener)("keydown", (ev) => {
    var _a;
    if (ev.code == "KeyZ" && ev.ctrlKey) {
      (_a = editor.current) == null ? void 0 : _a.back();
    }
  });
  return /* @__PURE__ */ React.createElement(import_util.Layout, { direction: "row", autoFit: true }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { flex: 1, style: { marginRight: 8 } }, /* @__PURE__ */ React.createElement(import_selectCtx.default, { editor, setCurrentFunc, sendParams: type.value })), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { flex: 2, direction: "column" }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { style: { marginTop: 5, position: "relative", overflow: "visible" } }, /* @__PURE__ */ React.createElement(import_textareaEditor.default, { ref: editor }), /* @__PURE__ */ React.createElement(
    "div",
    {
      style: {
        position: "absolute",
        right: 12,
        bottom: -38,
        display: "flex",
        alignItems: "center",
        gap: "8px"
      }
    },
    /* @__PURE__ */ React.createElement(
      import_functionalComponent.Button,
      {
        style: { zIndex: 99 },
        type: "primary",
        onClick: () => {
          var _a;
          return (_a = editor.current) == null ? void 0 : _a.back();
        },
        icon: /* @__PURE__ */ React.createElement(import_icons.RollbackOutlined, null)
      }
    ),
    /* @__PURE__ */ React.createElement(
      import_functionalComponent.Button,
      {
        style: { zIndex: 99, transform: "rotateY(180deg)" },
        type: "primary",
        onClick: () => {
          var _a;
          return (_a = editor.current) == null ? void 0 : _a.forward();
        },
        icon: /* @__PURE__ */ React.createElement(import_icons.RollbackOutlined, null)
      }
    ),
    /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { style: { zIndex: 99 }, type: "primary", onClick: () => {
      var _a;
      return (_a = editor.current) == null ? void 0 : _a.reset();
    } }, "清空"),
    /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { style: { zIndex: 99 }, type: "primary", onClick: validExpress }, "校验")
  )), /* @__PURE__ */ React.createElement(import_functionInfo.default, { currentFunc, childRef: getRef("FunctionInfo") })));
}
